﻿/*	@file	r_math_vector3.h
	@brief	3次元ベクトル
Copyright (c) 2009 Yuya Yamaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _R_MATH_VECTOR3_H_
#define _R_MATH_VECTOR3_H_

#include "../r_type.h"

namespace r{
	namespace math{

		struct Vector3D {
		public:
			//! コンストラクタ
			Vector3D();
			Vector3D ( r_f32 sx, r_f32 sy, r_f32 sz );
			Vector3D ( const r_f32 *sv );
			Vector3D ( const Vector3D &s );
		public:
			//! 比較
			r_bool		operator == ( const Vector3D &src ) const;
			r_bool		operator != ( const Vector3D &src ) const;

			//! 加算
			Vector3D	operator + ( const Vector3D &src ) const;
			//! 減算
			Vector3D	operator - ( const Vector3D &src ) const;
			//! 乗算
			Vector3D	operator * ( const Vector3D &src ) const;
			//! 乗算
			/*! 各要素をsrcで乗算します
			*/
			Vector3D	operator * ( const r_f32 &src ) const;
			//! 除算
			Vector3D	operator / ( const Vector3D &src ) const;
			//! 除算
			/*! 各要素をsrcで除算します
			*/
			Vector3D	operator / ( const r_f32 &src ) const;
			///
			const Vector3D&	operator += ( const Vector3D &src );
			///
			const Vector3D&	operator -= ( const Vector3D &src );
			///
			const Vector3D&	operator *= ( const Vector3D &src );
			///
			const Vector3D&	operator /= ( const Vector3D &src );
			///
			const Vector3D&	operator *= ( const r_f32 &src );
			///
			const Vector3D&	operator /= ( const r_f32 &src );
		public:
			//! ベクトルの内積を取得
			r_f32				dot ( const Vector3D &src ) const;
			//! ベクトルの外積を取得
			Vector3D			cross ( const Vector3D &src ) const;
			//! ベクトルの長さを取得
			r_f32				length ( void ) const;
			//! ベクトルの長さの2乗を取得
			r_f32				lengthsq ( void ) const;
			//! ベクトルの正規化
			const Vector3D&	normalize ( void );
			//! 正規化ベクトルの取得
			Vector3D			normal ( void ) const;
			//! ゼロ初期化
			void				zero ( void );
		public:
			union {
				struct {
					r_f32		x;
					r_f32		y;
					r_f32		z;
				};
				r_f32			v[3];
			};
		};
	}
}
#include "../rtti/r_rtti_reflection_typename.h"
namespace r{
	namespace rtti{
		//! r::math::Vector3D
		template<>
		static inline
		const r_cstr	getTypeNameStr<r::math::Vector3D>() {
			return _RST ( "r::math::Vector3D" );
		}
	}
}


#endif // _R_MATH_VECTOR3_H_
